<?php

namespace app\common\logic;

use app\common\model\CustomerServiceModel;

use app\common\model\ShopModel;



class KefuLogic{

    public static function getKefu($shop_id)

    {

        if(null !== $shop = ShopModel::find($shop_id)){

            if($shop->kefu){

                $kefu=[

                    'name'=>$shop->kefu->name,

                    'qrcode'=>$shop->kefu->qrcode,

                    'mobile'=>$shop->kefu->mobile,

                ];

            }

        }



        if(!isset($kefu)){

            $kefus=CustomerServiceModel::where([['is_delete','=',0]])->select()->toArray();

            if(!empty($kefus)){

                $kefu = $kefus[array_rand($kefus,1)] ?? [];

            }

        }



        if(!isset($kefu) || empty($kefu)){

            $kefu=[

                'name'=>'客服小李',

                'qrcode'=>null,

                'mobile'=>'1390000000',

            ];

        }



        return $kefu;

    }

}

